from Graph import Graph

def inputCityNames() :
    return (input("Starting location: "), input("Destination: "))

def printPath(path) :
    for i in range(len(path)) :
        if i == 0 :
            print(path[i].name, " -> ", end="", sep="")
        elif i < len(path) - 1 :
            print(path[i].name, "\n", path[i].name, " -> ", end="", sep="")
        else :
            print(path[i].name, "\n")

def main() :
    g = Graph()
    g.readNodes("./locations.csv")
    g.readLinks("./roads.csv")

    while True :
        print("1: Iterative Deepening Search")
        print("2: Best First Routing")
        print("3: A*-Search")
        print("4: Load nodes")
        print("5: Load links")
        print("6: Draw map")
        print("7: Print nodes")
        print("8: Print links")
        print("\n0: Exit")

        try :
            selection = int(input())
        except :
            selection = 0

        if selection == 1 :
            start, goal = inputCityNames()
            printPath(g.IDDFSearch(start, goal))   
                     
        elif selection == 2 :
            start, goal = inputCityNames()
            printPath(g.BFRSearch(start, goal))

        elif selection == 3 :
            start, goal = inputCityNames()
            printPath(g.AStarSearch(start, goal))

        elif selection == 4 :
            g.readNodes(input("File to load nodes from: "))

        elif selection == 5 :            
            g.readNodes(input("File to load links from: "))

        elif selection == 6 :
            g.drawMap()

        elif selection == 7 :
            g.printNodes()

        elif selection == 8 :
            g.printLinks()

        else :
            break

main()

#g = Graph()
#g.readNodes("./locations.csv")
#g.readLinks("./roads.csv")
#g.printNodes()
#g.printLinks()
#g.getLinkDist(g.links[0])
#g.drawMap()
#printPath(g.AStarSearch("Oberdolling", "Eichstatt"))
